import 'package:dio/dio.dart';

class DioStatic {
  static DioStatic? _instance;

  static DioStatic getInstance() {
    if (_instance == null) {
      _instance = DioStatic._init();
    }
    return _instance!;
  }

  String accessToken = "";
  String refreshToken = "";

  DioStatic._init();

  final Dio dio = Dio()
    ..interceptors.add(LogInterceptor(responseBody: true))
    ..options.headers['Content-Type'] = 'application/x-www-form-urlencoded'
  ;

  void init() {
    dio.interceptors.add(LogInterceptor(responseBody: true));
    dio.options.headers['Content-Type'] = 'application/json';
    // dio.interceptors.add(ErrorInterceptor());
  }

  void initToken(String? accessToken, String? refreshToken) {
    if (accessToken!= null && refreshToken!= null) {
      this.accessToken = accessToken;
      this.refreshToken = refreshToken;
      dio.options.headers['Authorization'] =  accessToken;
    }
  }
}
